package com.sg.service.biz.bff.impl;

import cn.hutool.core.bean.BeanUtil;
import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.bff.req.*;
import com.sg.dto.biz.bff.res.*;
import com.sg.service.biz.bff.NullService;
import com.wicket.okrframework.integration.InductionRecordService;
import com.wicket.okrframework.integration.NullService;
import com.wicket.okrframework.integration.RoleService;
import com.wicket.okrframework.integration.dto.*;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.stream.Collectors;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class NullServiceImpl implements NullService {

    @Resource
    com.sg.service.biz.framework.NullService NullClient;
    @Resource
    com.sg.service.biz.framework.NullService fwBaseNullClient;
    @Resource
    com.sg.service.biz.framework.InductionRecordService fwBaseInductionRecordClient;
    @Resource
    com.sg.service.biz.framework.RoleService fwBaseRoleClient;
    @Resource
    private RedisUtil redisUtil;

    /**
     * B1-3批量新增部门岗位职务关系（管理）[962]
     */
    @Trace(operationName = "B1-3批量新增部门岗位职务关系（管理）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffBatchAddDeptPositionRespDto batchAddDeptPosition(BffBatchAddDeptPositionReqDto reqDto) {


        //步骤0: D1-3批量新增部门岗位职务关系 - batchAddDeptPosition
        BatchAddDeptPositionRespDto batchAddDeptPositionRespDto = null;
        BatchAddDeptPositionReqDto batchAddDeptPositionReqDto = new BatchAddDeptPositionReqDto();
        if (reqDto != null) {
            batchAddDeptPositionReqDto.setOrgDeptPositionList(reqDto.getOrgDeptPositionList().stream().map(item -> BeanUtil.toBean(item, OrgDeptPositionDto.class)).collect(Collectors.toList()));//sourceId:40074_1
        }

        /*D1-3批量新增部门岗位职务关系[1496]   */
        batchAddDeptPositionRespDto = fwBaseNullClient.batchAddDeptPosition(batchAddDeptPositionReqDto).getData();


        BffBatchAddDeptPositionRespDto retData = new BffBatchAddDeptPositionRespDto();


        return retData;
    }

    /**
     * B1-3查询想存档部门岗位职务条件（管理）
     */
    @Trace(operationName = "B1-3查询想存档部门岗位职务条件（管理）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffQueryArchiveDeptPositionRespDto queryArchiveDeptPosition(BffQueryArchiveDeptPositionReqDto reqDto) {


        //步骤0: D1-3查就职记录列表 - queryInductionRecordList
        QueryInductionRecordListRespDto queryInductionRecordListRespDto = null;
        QueryInductionRecordListReqDto queryInductionRecordListReqDto = new QueryInductionRecordListReqDto();
        queryInductionRecordListReqDto.setIsArchive("FALSE");//sourceId:40889_1
        if (reqDto != null) {
            queryInductionRecordListReqDto.setOrganizationId(reqDto.getOrganizationId());//sourceId:40896_1
            queryInductionRecordListReqDto.setDeptPositionRelationshipId(reqDto.getDeptPositionRelationshipId());//sourceId:40878_1
        }

        /*D1-3查就职记录列表[1505]   */
        queryInductionRecordListRespDto = fwBaseInductionRecordClient.queryInductionRecordList(queryInductionRecordListReqDto).getData();


        BffQueryArchiveDeptPositionRespDto retData = new BffQueryArchiveDeptPositionRespDto();
        retData.setOrgInductionRecordList(queryInductionRecordListRespDto.getOrgInductionRecordList().stream().map(inc -> inc.getInductionRecordId()).collect(Collectors.toList()));//sourceId:40899_1


        return retData;
    }

    /**
     * B1-2撤销存档自定义角色（管理）
     */
    @Trace(operationName = "B1-2撤销存档自定义角色（管理）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffUndoArchiveCustomizeRoleMemberRespDto undoArchiveCustomizeRoleMember(BffUndoArchiveCustomizeRoleMemberReqDto reqDto) {


        //步骤0: D1-2修改自定义角色 - updateCustomRole
        UpdateCustomRoleRespDto updateCustomRoleRespDto = null;
        UpdateCustomRoleReqDto updateCustomRoleReqDto = new UpdateCustomRoleReqDto();


        /*D1-2修改自定义角色[640]   */
        updateCustomRoleRespDto = fwBaseRoleClient.updateCustomRole(updateCustomRoleReqDto).getData();


        BffUndoArchiveCustomizeRoleMemberRespDto retData = new BffUndoArchiveCustomizeRoleMemberRespDto();


        return retData;
    }

    /**
     * B1-2发布自定义角色（管理）
     */
    @Trace(operationName = "B1-2发布自定义角色（管理）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffReleaseCustomizeRoleMemberRespDto releaseCustomizeRoleMember(BffReleaseCustomizeRoleMemberReqDto reqDto) {


        //步骤0: D1-2修改自定义角色 - updateCustomRole
        UpdateCustomRoleRespDto updateCustomRoleRespDto = null;
        UpdateCustomRoleReqDto updateCustomRoleReqDto = new UpdateCustomRoleReqDto();


        /*D1-2修改自定义角色[640]   */
        updateCustomRoleRespDto = fwBaseRoleClient.updateCustomRole(updateCustomRoleReqDto).getData();


        BffReleaseCustomizeRoleMemberRespDto retData = new BffReleaseCustomizeRoleMemberRespDto();


        return retData;
    }

    /**
     * B1-2删除自定义角色（管理）
     */
    @Trace(operationName = "B1-2删除自定义角色（管理）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffDeleteCustomizeRoleMemberRespDto deleteCustomizeRoleMember(BffDeleteCustomizeRoleMemberReqDto reqDto) {


        //步骤0: D1-2删除自定义角色 - deleteRole
        DeleteRoleRespDto deleteRoleRespDto = null;
        DeleteRoleReqDto deleteRoleReqDto = new DeleteRoleReqDto();


        /*D1-2删除自定义角色[641]   */
        deleteRoleRespDto = fwBaseNullClient.deleteRole(deleteRoleReqDto).getData();


        BffDeleteCustomizeRoleMemberRespDto retData = new BffDeleteCustomizeRoleMemberRespDto();


        return retData;
    }
    //
}
